/*
网站管理员Store，超级客服，拥有所有权限
*/

import { defineStore } from "pinia";
import type { Ref } from "vue";
import { computed, ref } from "vue";

import type {
  IWebsite,
  
  IWebsiteService,
  ICustomer,

  IConversation,
  IConversationRelation,
} from "@src/types";

const useCustomerStore = defineStore("useCustomerStore", () => {

  //来自url的用户id，可能是随机的，也可能是第三方的，发送给服务端后，服务端可能会进行修改，比如匹配到了关联的id
  const customerId: Ref<string | undefined> = ref(undefined);
  // const serviceId: Ref<string | undefined> = ref(undefined);
  // app data refs
  // data refs
  const services: Ref<Record<string,IWebsiteService>> = ref({});
  const customer: Ref<ICustomer | undefined> = ref(undefined);
  
  const website: Ref<IWebsite | undefined> = ref(undefined);
  const conversations: Ref<Record<string,IConversation>> = ref({});

  const conversationRelation: Ref<IConversationRelation | undefined> = ref(undefined);

  const infoId: Ref<String | undefined> = ref(undefined);

  function addConversation(conversation:IConversation) {
    conversations.value[conversation.id] = conversation;
  }

  const loadMoreFlag: Ref<Boolean> = ref(false);

  
  return {
    infoId,
    loadMoreFlag,
    conversationRelation,
    addConversation,
    customerId,
    services,
    website,
    conversations,
    customer
  };
});

export default useCustomerStore;
